package com.kollway.imageselector;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.support.v4.app.Fragment;

import com.kollway.imageselector.activity.PictureSelectorActivity;

/**
 * Created by chenxiabin on 03/01/2017.
 */

public class PictureSelector {

    private Intent selectorIntent;

    public static PictureSelector make() {
        return new PictureSelector();
    }

    private PictureSelector() {
        selectorIntent = new Intent();
    }

    /**
     * 是否可预览
     *
     * @param isPreview
     * @return
     */
    public PictureSelector setPreview(boolean isPreview) {
        selectorIntent.putExtra(PictureSelectorActivity.SP_PICTURE_SELECTOR_PREVIEW, isPreview);
        return this;
    }

    /**
     * 可选最大数量
     *
     * @param num
     * @return
     */
    public PictureSelector setMaxNum(int num) {
        selectorIntent.putExtra(PictureSelectorActivity.SP_PICTURE_SELECTOR_MAX, num);
        return this;
    }

    /**
     * 是否需要拍照
     *
     * @param isTakePhoto
     * @return
     */
    public PictureSelector setTakePhoto(boolean isTakePhoto) {
        selectorIntent.putExtra(PictureSelectorActivity.SP_PICTURE_SELECTOR_TAKE_PHOTO, isTakePhoto);
        return this;
    }

    public void start(Activity activity, int request) {
        activity.startActivityForResult(getIntent(activity), request);
    }

    public void start(Fragment fragment, int request) {
        fragment.startActivityForResult(getIntent(fragment.getContext()), request);
    }

    private Intent getIntent(Context context) {
        selectorIntent.setClass(context, PictureSelectorActivity.class);
        return selectorIntent;
    }
}
